//
//  YTOrderDetailViewModel.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/6/21.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTOrderDetailViewModel.h"
#import "YTOrderServices.h"
#import "YTCarAndBonusModel.h"
#import "YTOrderDetailModel.h"

@interface YTOrderDetailViewModel ()
@property (strong, nonatomic, readwrite) RACCommand *detailCommand;
@end

@implementation YTOrderDetailViewModel

- (void)initialize {
    [super initialize];
    _dataModel = [[YTOrderDetailModel alloc] init];
    [self loadDataCmd];
    [self pickCmd];
}

// 获取订单model数据
- (void)loadDataCmd {
    @weakify(self);
    _detailCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(NSString *order_id) {
        @strongify(self);
        return [[YTOrderServices loadOrderDetailWithId:order_id] map:^id(NSDictionary *response) {
            self.dataModel = [YTOrderDetailModel yy_modelWithJSON:response[@"responseData"]];
            return self.dataModel;
        }];
    }];
}

- (void)pickCmd {
    @weakify(self);
    _loadCarAndBonusCmd = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        dict[@"orderId"] = self.dataModel.orderId;
        dict[@"applyStatus"] = @"1";
        dict[@"status"] = @"1";
        dict[@"maxPassenger"] = self.dataModel.staffNum;
        dict[@"maxLuggage"] = self.dataModel.luggage;
        return [[YTOrderServices getCarAndCoupon:dict] doNext:^(NSDictionary *response) {
            @strongify(self);
            self.carBonusModel = [YTCarAndBonusModel yy_modelWithJSON:response[@"responseData"]];
        }];
    }];
    
    _pickOrderCmd = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(RACTuple *carAndBonus) {
        @strongify(self);
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        dict[@"carId"] = carAndBonus.first;
        dict[@"orderId"] = self.dataModel.orderId;
        dict[@"couponKey"] = carAndBonus.second;
        dict[@"maxPassenger"] = self.dataModel.staffNum;
        dict[@"maxLuggage"] = self.dataModel.luggage;
        return [YTOrderServices pickeOrderWith:dict];
    }];
}

#pragma mark -

@end
